package com.xs.anxingo.server.api.impl;

import com.xs.anxingo.server.helper.APIHelper;
import com.xs.anxingo.server.api.HouseAPI;
import com.xs.anxingo.server.api.req.AddHouseInfoRequest;
import com.xs.anxingo.server.api.resp.BaseResponse;
import com.xs.anxingo.server.api.service.HouseAPIService;
import com.xs.anxingo.server.exception.BusinessException;
import com.xs.anxingo.server.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2019/12/10.
 */
@Slf4j
@SuppressWarnings("ALL")
@Service("houseAPI")
public class HouseAPIImpl implements HouseAPI {

    @Autowired
    private HouseAPIService houseAPIService;

    /**
     * 新增房产信息
     *
     * @param reqString
     * @return
     */
    @Override
    public String addHouseInfo(String reqString) {
        log.error("==>HouseAPIImpl.addHouseInfo BEGIN,reqString={}", reqString);

        APIHelper.checkReqString(reqString);
        AddHouseInfoRequest request = JsonUtil.toObject(reqString, AddHouseInfoRequest.class);
        APIHelper.checkRequest(request);

        BaseResponse response = BaseResponse.buildSuccess();
        try {
            houseAPIService.doAddHouseInfo(request);
        } catch (BusinessException e) {
            log.error("HouseAPIImpl.addHouseInfo ERROR,e={}", e);
        }

        log.error("==>HouseAPIImpl.addHouseInfo END,response={}", JsonUtil.toJson(response));
        return JsonUtil.toJson(response);
    }
}
